/*
 * @Author: '浪川' '1214391613@qq.com'
 * @Date: 2025-07-05 16:06:20
 * @LastEditors: '浪川' '1214391613@qq.com'
 * @LastEditTime: 2025-07-07 11:21:14
 * @FilePath: \passiflora-edulis-sims\src\stores\scramble-store.ts
 * @Description: 单词拼写 的 状态管理
 *
 * Copyright (c) 2025 by '1214391613@qq.com', All Rights Reserved.
 */
import { defineStore, acceptHMRUpdate } from 'pinia'
import type { IScramble } from 'src/interfaces/Puzzle/ICrossword'

export const useScrambleStore = defineStore('scramblerch', {
  state: (): IScramble => ({
    title: 'scramblerch Puzzle',
    title_font_size: 24,
    title_font_color: '#703030',
    instruction: 'scramblerch Puzzle Level2',
    instruction_font_size: 0,
    instruction_font_color: '#000000',
    words_list: {},
    words_font_size: 10,
    puzzle_size: [5000, 5000],
    box_width: 500,
    box_color: '#000000',
    stroke_width: 5,
    text_color: '#000000',
    input_words_textarea:
      'House Sparrow\nStarling\nBlackbird\nBlue Tit\nGoldfinch\nPigeon\nCrow\nMagpie\nWoodpecker\nWren',
  }),

  getters: {
    words(): string[] {
      /**
       * @description: 将textare 区域的文本值改为s
       * @param {string} text
       * @return {*} Record<string, string>
       */
      const wds: string[] = []
      this.input_words_textarea.split('\n').forEach((line) => {
        if (!line.trim()) return // 跳过空行

        wds.push(line.trim()) // 处理值中可能包含的冒号
      })

      return wds
    },
    max_wordlen(): number {
      let num = 0
      for (const str of this.words) {
        num = str.length > num ? str.length : num
      }
      return num
    },
  },

  actions: {},
})

if (import.meta.hot) {
  import.meta.hot.accept(acceptHMRUpdate(useScrambleStore, import.meta.hot))
}
